package com.xiaoshuaila.settings.service;

import com.xiaoshuaila.exception.loginexception;
import com.xiaoshuaila.settings.dao.userdao;
import com.xiaoshuaila.settings.domain.user;
import com.xiaoshuaila.settings.service.userservice;
import com.xiaoshuaila.tool.*;

import java.util.List;

public class userserviceImpl implements userservice {
    private userdao userdao=
            SqlSessionUtil.getSqlSession().getMapper(userdao.class);

    @Override
    public user login(user user) throws loginexception {
       user list=userdao.login(user);
       if(list==null)
       {
           throw new loginexception("账号密码错误！");
       }
       if (list.getExpireTime().compareTo(DateTimeUtil.getSysTime())<0)
       {
           throw new loginexception("账号已失效");
       }
       if("0".equals(list.getLockState()))
           throw new loginexception("账号已被锁定");
       if(!list.getAllowIps().contains(user.getAllowIps()))
           throw new loginexception("ip地址受限制");
        return list;
    }
}
